package summative;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFileChooser;
import javax.swing.JMenuItem;

public class FileListener implements ActionListener
{
	JMenuItem item;
	JFileChooser chooser = new JFileChooser();
	private GetInformation information;
	private VectorList list;
	
	public FileListener(JMenuItem item, VectorList list)
	{
		this.item = item;
		this.list = list;
	}

	public void createJFileChooser()
	{
		this.addFilterToChooser();
		chooser.showOpenDialog(null);
	}
	
	public void addFilterToChooser()
	{
		chooser.setFileFilter(new FileExtended());
	}
	
	public void actionPerformed(ActionEvent e)
	{
		this.createJFileChooser();
		
		try{
			information = new GetInformation(chooser.getSelectedFile());
			
			for(int x = 0; x<information.calculateNumber(); x++)
			{
				System.out.println(information.getText());
				list.addVector(information.getText());
			}
			
			
			
		}catch(NullPointerException ex){
		}
	}

}
